// pages/index/index.js
import request  from "../../utils/request";

Page({

  /**
   * 页面的初始数据
   */
  data: {
      bannerList:[],//  轮播图
      recommendList:[],// 推荐歌单
      topList:[],// 排行榜数据
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
   let bannerListData = await request("/banner",{type:2})

    this.setData({
      bannerList : bannerListData.banners
    })
    let recommendListData = await request("/personalized",{limit:10})
    this.setData({
      recommendList : recommendListData.result
    })
      let topListData = await request("/toplist")
      let tempList = topListData.list

      let resultArray = []
      for (let i = 0; i < 5; i++) {
          let topListItem = tempList.slice(i * 3, (i+1) * 3)
          resultArray.push(topListItem)
      }
    this.setData({
        topList : resultArray
    })
  },
    recommendList(){
      wx.navigateTo({
          url:"/songPackage/pages/recommendSong/recommendSong"
      })
    },
    toOther(){
      wx.navigateTo({
          url: "/otherPackage/pages/other/other"
      })
    },
    collectSongList(){
        wx.navigateTo({
            url:"/songPackage/pages/collectSong/collectSong"
        })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})